package com.hhs.storage.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhs.storage.bean.*;
import com.hhs.storage.bean.dto.ContractClient;
import com.hhs.storage.dao.ContractDao;
import com.hhs.storage.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhs.storage.util.SysUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hhs
 * @since 2022-11-30
 */
@Service
@Transactional
public class ContractServiceImpl extends ServiceImpl<ContractDao, Contract> implements ContractService {
    @Resource
    ParticipleServiceImpl participleService;
    @Resource
    private HttpServletRequest request;
    @Resource
    ImgService imgService;
    @Resource
    BaseRoleService roleService;
    @Resource
    BusinessDocumentService businessDocumentService;
    @Resource
    ComsumerService comsumerService;
    @Resource
    private BaseDepartmentService departmentService;
    @Resource
    FlowService flowService;
    @Autowired
    private ContractProductSupplierService contractProductSupplierService;
    @Override
    public Map addOrEdit(Contract contract, HttpServletRequest request,String deleIdStr , MultipartFile[] photoList) {
        String createrId = SysUtil.getLoginUserId(request);
        if( StringUtils.isEmpty(createrId)){
            return ResponseInfo.error("参数错误，请重新填入");
        }
        if(contract.getIsExtension()!=null &&contract.getIsExtension()==1){
            //若合同已经选择续期，则不用提醒
            contract.setIsExpireCaution(0);
        }else{
            //合同到期要提醒
            contract.setIsExpireCaution(1);
        }

        //将客户信息取出来，放入comsumer内，并设置到firstparty属性
        ContractClient temp = JSON.parseObject(contract.getClientObj(), new TypeReference<ContractClient>(){});
//        String firstParty = comsumerService.addForContractClient(temp, createrId);
        String firstParty = "测试";
        if(StringUtils.isEmpty(firstParty)){
            return ResponseInfo.error("参数错误，请填入客户信息");
        }else{
            //原来甲方的属性，现在不区分甲乙方了，直接放客户数据id
            contract.setFirstParty(firstParty);
        }
        //新增合同记录
        if(StringUtils.isEmpty(contract.getId())){
            return add(contract,createrId,photoList);
        }else{
            //修改记录
            if(contract.getStatus().equals(Contract.STATUS_TEMP)){
                //临时合同的修改
                return editTemp(contract,createrId,deleIdStr,photoList);
            }
            return edit(contract,createrId,deleIdStr,photoList);
        }
    }

    private Map  add(Contract contract, String createrId, MultipartFile[] photoList){
        //创建合同对象
        //若是业务员自己，则负责人是自己
//        boolean flag= roleService.hasRole(SysUtil.ROLE_FLAG_YWY,createrId);
//        if(flag){
            contract.setPrincipal(createrId);
//        }
        contract.setId(SysUtil.UUID());
        contract.setCreateTime(LocalDateTime.now());
        contract.setCreater(createrId);
        contract.setStatus(Contract.STATUS_CREATE);
        System.out.println(123);
        //写入合同对象到数据库
        this.save(contract);
        //合同有图片则保存图片
        if (photoList!=null){
            if(photoList.length>0){
                imgService.upload( SysUtil.CONTRACT,contract.getId(),photoList);
            }
        }

        //添加产品供货商,删除原有，添加新供货商
        addProductSuppliers(contract);


//        if(contract.getContractType().equals(SysUtil.TEMP_CONTRACT_TYPEID)){
        if(contract.getIsTemp()!=null && contract.getIsTemp().equals(1)){
            //临时合同类型 特殊处理，创建即为状态值5
            contract.setStatus(Contract.STATUS_TEMP);
            //不进行到期提醒
            contract.setIsExpireCaution(0);
            updateById(contract);
            //流程直接结束
            flowService.createWithEndTime(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_CREATE,contract.getId(),createrId,"创建临时合同");
            flowService.create(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"提交待初审");
            return ResponseInfo.success();
        }
        //开始走流程，生成流程对象
        flowService.createWithEndTime(Flow.TYPE_CONTRACT, Contract.STATUS_CREATE,contract.getId(),createrId,"创建合同");
        flowService.create(Flow.TYPE_CONTRACT, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"提交待初审");
        //新增分词
        Participle participle = new Participle();
        participle.setName(contract.getProject());
        InputParam inputParam = new InputParam();
        participleService.add(participle,inputParam);

//        participleService.add();
        return ResponseInfo.success();
    }

    /**
     * 添加产品供货商,删除原有，添加新供货商
     * @param contract
     */
    private void addProductSuppliers(Contract contract) {
        QueryWrapper<ContractProductSupplier> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("contract_id",contract.getId());
        contractProductSupplierService.remove(queryWrapper);
        if( !StringUtils.isEmpty(contract.getProductSupplierIds())){
            String[] ids=contract.getProductSupplierIds().split(",");
            for (int i=0;i<ids.length;i++){
                ContractProductSupplier contractProductSupplier=new ContractProductSupplier();
                contractProductSupplier.setId(SysUtil.UUID());
                contractProductSupplier.setContractId(contract.getId());
                contractProductSupplier.setProductSupplierId(ids[i]);
                contractProductSupplierService.save(contractProductSupplier);
            }
        }
    }

    private Map  edit(Contract contract,  String createrId,String deleIdStr , MultipartFile[] photoList){
        if(StringUtils.isEmpty(contract.getProject()) ){
            return ResponseInfo.error("参数错误，请重新填入");
        }
        //写入合同对象到数据库
        this.updateById(contract);
        //合同有图片则保存图片
        if(photoList.length>0){
            imgService.upload( SysUtil.CONTRACT,contract.getId(),photoList);
        }
        //删除图片
        if(!StringUtils.isEmpty(deleIdStr)){
            String[] deleIdArr = deleIdStr.split(",");
            if(deleIdArr.length>0){
                for (String id : deleIdArr) {
                    imgService.deleById(id);
                }
            }
        }
        //添加产品供货商,删除原有，添加新供货商
        addProductSuppliers(contract);
        //查询合同当前未结束的流程
        Flow current = flowService.getCurrent(contract.getId());
        if(current!=null){
            //流程还在审核途中
            //如果当前流程是初审被驳回，status回到新建状态 且修改人为合同的录入人员
            if(current.getStatus()==Contract.STATUS_CREATE &&
                    current.getStatusJunior().equals(Contract.STATUS_JUNIOR_RETURN)
                && createrId.equals(contract.getCreater())){
                current.setEndTime(LocalDateTime.now());
                flowService.updateById(current);
                //先设置修改记录
                flowService.createWithEndTime(Flow.TYPE_CONTRACT, Contract.STATUS_MODIFY,contract.getId(),createrId,"初审驳回后，修改合同数据");
                //再重新进入初审流程
                flowService.create(Flow.TYPE_CONTRACT, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"提交待初审");
            }else {
                //流程表记录修改记录
                flowService.createWithEndTime(Flow.TYPE_CONTRACT, Contract.STATUS_MODIFY, contract.getId(), createrId, "修改合同");
            }
        }else {
            //流程表记录修改记录
            flowService.createWithEndTime(Flow.TYPE_CONTRACT, Contract.STATUS_MODIFY, contract.getId(), createrId, "修改合同");
        }
        return ResponseInfo.success();
    }

    //临时合同的修改
    private Map  editTemp(Contract contract,  String createrId,String deleIdStr , MultipartFile[] photoList){
        if(StringUtils.isEmpty(contract.getProject()) ){
            return ResponseInfo.error("参数错误，请重新填入");
        }
        //写入合同对象到数据库
        this.updateById(contract);
        //合同有图片则保存图片
        if(photoList.length>0){
            imgService.upload( SysUtil.CONTRACT,contract.getId(),photoList);
        }
        //删除图片
        if(!StringUtils.isEmpty(deleIdStr)){
            String[] deleIdArr = deleIdStr.split(",");
            if(deleIdArr.length>0){
                for (String id : deleIdArr) {
                    imgService.deleById(id);
                }
            }
        }
        //添加产品供货商,删除原有，添加新供货商
        addProductSuppliers(contract);

        //查询合同当前未结束的流程
        Flow current = flowService.getCurrent(contract.getId());
        if(current!=null){
            //流程还在审核途中
            //如果当前流程是初审被驳回，status回到新建状态 且修改人为合同的录入人员
            if(current.getStatus()==Contract.STATUS_CREATE &&
                    current.getStatusJunior().equals(Contract.STATUS_JUNIOR_RETURN)
                    && createrId.equals(contract.getCreater())){
                current.setEndTime(LocalDateTime.now());
                flowService.updateById(current);
                //先设置修改记录
                if(contract.getIsTemp().equals(1)){
                    //临时合同新建
                    flowService.createWithEndTime(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_MODIFY,contract.getId(),createrId,"临时合同初审驳回后，修改合同数据");
                    //再重新进入初审流程
                    flowService.create(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"临时合同，提交待初审");
                }else{
                    //临时合同转正式
                    flowService.createWithEndTime(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_MODIFY,contract.getId(),createrId,"临时合同转正式，初审驳回后，修改合同数据");
                    flowService.create(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"临时合同转正式，提交待初审");
                }
            }else {
                //流程表记录修改记录
                flowService.createWithEndTime(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_MODIFY, contract.getId(), createrId, "修改合同数据");
            }
        }else {
            if(createrId.equals(contract.getCreater())){
                //修改人为合同的录入人员 并且之前没有流程，表示要开始进入临时合同的审核流程
                flowService.create(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_CHECK,Contract.STATUS_JUNIOR_DEAL,contract.getId(),createrId,"临时合同转正式，提交待初审");
            }else {
                //流程表记录修改记录
                flowService.createWithEndTime(Flow.TYPE_CONTRACT_TEMP, Contract.STATUS_MODIFY, contract.getId(), createrId, "临时合同转正式，修改合同数据");
            }
        }
        return ResponseInfo.success();
    }


    @Override
    public Map<String, Object> getAll(InputParam inputParam) throws IOException, ClassNotFoundException {
        QueryWrapper ew = new QueryWrapper<BaseUser>();
        if(inputParam.getStatus()!=null) {
            ew.eq("status", inputParam.getStatus());
        }else if(inputParam.getQueryType().equals(3)){
            //我的录入 查询新建 1以及临时 5
            ew=new QueryWrapper<Flow>().and(i -> i.eq("status", 1)
                            .or().eq("status", 5));
        }

        if(!StringUtils.isEmpty(inputParam.getProject())){
            ew.like("project",inputParam.getProject());
        }
        if(!StringUtils.isEmpty(inputParam.getCurUserId())){
            ew.eq("creater",inputParam.getCurUserId());
        }
        if(!StringUtils.isEmpty(inputParam.getContractType())){
            ew.eq("contract_type",inputParam.getContractType());
        }
        /**
         * 根据当前登录用户身份查询数据
         */
        String userId=SysUtil.getLoginUserId(request);
        if(roleService.hasRole(SysUtil.ROLE_FLAG_JL,userId )){//当前用户是经理
            //查询经理负责部门下所有部门下属负责的合同
            List<BaseUser> userList=departmentService.getUserDepartAllUser(userId);
            List<String> idList = new ArrayList<>();
            for (int i = 0; i < userList.size(); i++) {
                idList.add( userList.get(i).getId());
            }
            ew.in("principal",idList);
        }else if(roleService.hasRole(SysUtil.ROLE_FLAG_YWY,userId )){//当前用户是ywy
            //查询合同是当前业务员负责的
            ew.eq("principal",userId);
        }

        ew.orderByDesc("create_time");
        Page<Contract> result = this.page(new Page<Contract>(
                inputParam.getPage(),
                inputParam.getSize()),ew);

//        if(inputParam.getStatus()!=Contract.STATUS_FINISHED) {
            //在审核途中的合同，才去查询流程
            for (Contract con : result.getRecords()) {
                InputParam temp = new InputParam();
                temp.setMainId(con.getId());
                List<Flow> flowList = flowService.getListAndCreater(temp);
                con.setFlowList(flowList);
                //设置合同当前流程，查出流程里endtime为空的数据
                for (Flow flow : flowList) {
                    if(flow.getEndTime()==null){
                        //深拷贝对象，防止json转换出错
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(bos);
                        oos.writeObject(flow);
                        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
                        ObjectInputStream ois = new ObjectInputStream(bis);
                        Flow newFlow = (Flow) ois.readObject();
                        con.setCurFlow(newFlow);
                    }
                }

            }
//        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", result.getRecords());
        map.put("total",result.getTotal());
        map.put("code", 1);
        return map;
    }

    @Override
    public Map<String, Object> query(Contract contract, InputParam inputParam) throws IOException, ClassNotFoundException {
        QueryWrapper ew = new QueryWrapper<Contract>();
        if(inputParam.getStatus()!=null) {//合同状态
            ew.eq("status", inputParam.getStatus());
        }
        if(!StringUtils.isEmpty(contract.getProject())){//项目名称
            Participle participle = new Participle();
            InputParam inputParam1 = new InputParam();
            Map map = participleService.getAll(participle,inputParam1);
            System.out.println("123");
            List<Participle> list = (List) map.get("rows");
            List queryList = new ArrayList();
            queryList.add(contract.getProject());
            for (Participle participleList : list) {
                String upStr = contract.getProject().toUpperCase();
                if (participleList.getInitial().equals(upStr) || participleList.getInitial().equals(upStr)){
//                    System.out.println(participleList.getParticiple());
                    queryList.add(participleList.getParticiple());
                }
            }
//            System.out.println(queryList);
            ew.like("project",contract.getProject());
        }
        if(!StringUtils.isEmpty(contract.getFirstParty())){//甲方
            ew.eq("first_party",contract.getFirstParty());
        }
        if(!StringUtils.isEmpty(contract.getSecondParty())){//乙方
            ew.eq("second_party",contract.getSecondParty());
        }
        if(!StringUtils.isEmpty(contract.getContractType())){//合同类型
            ew.eq("contract_type",contract.getContractType());
        }

        if(!StringUtils.isEmpty(contract.getModelType())){//型号
            ew.eq("model_type",contract.getModelType());
        }
        if(!StringUtils.isEmpty(contract.getPayType())){//付款类型
            ew.eq("pay_type",contract.getPayType());
        }
        if(!StringUtils.isEmpty(contract.getPayWay())){//付款性质
            ew.eq("pay_way",contract.getPayWay());
        }
        if(contract.getIsExtension()!=null){//续约
            ew.eq("is_extension",contract.getIsExtension());
        }
        if(inputParam.getSignStartTime()!=null){//签约时间
            ew.ge("sign_time",inputParam.getSignStartTime());
        }
        if(inputParam.getSignEndTime()!=null){//签约时间
            ew.le("sign_time",inputParam.getSignEndTime());
        }
        if(inputParam.getEndStartTime()!=null){//截止时间
            ew.ge("end_time",inputParam.getEndStartTime());
        }
        if(inputParam.getEndEndTime()!=null){//截止时间
            ew.le("end_time",inputParam.getEndEndTime());
        }
        if(!StringUtils.isEmpty(inputParam.getCurUserId())){
            ew.eq("creater",inputParam.getCurUserId());
        }
        /**
         * 根据当前登录用户身份查询数据
         */
        String userId=SysUtil.getLoginUserId(request);
        if(roleService.hasRole(SysUtil.ROLE_FLAG_JL,userId )){//当前用户是经理
            //查询经理负责部门下所有部门下属负责的合同
            List<BaseUser> userList=departmentService.getUserDepartAllUser(userId);
            List<String> idList = new ArrayList<>();
            for (int i = 0; i < userList.size(); i++) {
                idList.add( userList.get(i).getId());
            }
            ew.in("principal",idList);
        }else if(roleService.hasRole(SysUtil.ROLE_FLAG_YWY,userId )){//当前用户是ywy
            //查询合同是当前业务员负责的
            ew.eq("principal",userId);
        }

        ew.orderByDesc("create_time");
        Page<Contract> result = this.page(new Page<Contract>(
                inputParam.getPage(),
                inputParam.getSize()),ew);

//        if(inputParam.getStatus()!=Contract.STATUS_FINISHED) {
            //在审核途中的合同，才去查询流程
            for (Contract con : result.getRecords()) {
                InputParam temp = new InputParam();
                temp.setMainId(con.getId());
                List<Flow> flowList = flowService.getListAndCreater(temp);
                con.setFlowList(flowList);
                //设置合同当前流程
                for (Flow flow : flowList) {
                    if(flow.getEndTime()==null){
                        //深拷贝对象，防止json转换出错
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(bos);
                        oos.writeObject(flow);
                        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
                        ObjectInputStream ois = new ObjectInputStream(bis);
                        Flow newFlow = (Flow) ois.readObject();
                        con.setCurFlow(newFlow);
                    }
                }

//            }
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", result.getRecords());
        map.put("total",result.getTotal());
        map.put("code", 1);
        return map;
    }

    @Override
    public Map<String, Object> queryBySelfContract(Contract contract, InputParam inputParam) throws IOException, ClassNotFoundException {
        //获取自己创建的，并且是终审过后的合同，在合同结束时间内或者自动续期的
//        QueryWrapper ew = new QueryWrapper<Contract>();
//        if(!StringUtils.isEmpty(inputParam.getProject())){//项目名称
//            ew.like("project",inputParam.getProject());
//        }
//        //查询与自身相关合同
//        ew.eq("creater",SysUtil.getLoginUserId(request));
//        // 查询状态为7或5的合同
//        ew.in("status",Contract.STATUS_FINISHED,Contract.STATUS_TEMP);
//
//        ew.orderByDesc("create_time");
//        Page<Contract> result = this.page(new Page<Contract>(
//                inputParam.getPage(),
//                inputParam.getSize()),ew);
//        Map<String, Object> map = new HashMap<String, Object>();
//        map.put("rows", result.getRecords());
//        map.put("total",result.getTotal());
//        map.put("code", 1);
        inputParam.setOffset((inputParam.getPage()-1)*inputParam.getSize());
        inputParam.setCurUserId(SysUtil.getLoginUserId(request));
        List<Contract> list = this.baseMapper.queryBySelfContract(inputParam);
        long l = this.baseMapper.queryBySelfContractCount(inputParam);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("rows", list);
        map.put("total",l);
        map.put("code", 1);
        return map;
    }

    @Override
    public Map dele(String id) {

        if(!StringUtils.isEmpty(id)) {
            //查询合同的关联下单数据
            QueryWrapper ew = new QueryWrapper<BusinessDocument>();
            ew.eq("contract_id",id);
            List list = businessDocumentService.list(ew);
            if(list.size()>0){
                return ResponseInfo.error("该合同已报单，无法删除");
//                //有单据则状态标识为废弃
//                Contract contract = this.getById(id);
//                contract.setStatus(Contract.STATUS_DELETE);
//                this.updateById(contract);
            }else {//合同没有单据，则直接删除
                //删除对应的客户ccomsumer表的数据 ，等需求不再变更了，改成级联
                Contract contract = this.getById(id);
                comsumerService.removeById(contract.getFirstParty());
                //找到合同的图片，删除图片
                Img img = new Img();
                img.setMainId(id);
                List<Img> imgList = imgService.getByMainId(img);
                for (Img img1 : imgList) {
                    imgService.deleById(img1.getId());
                }
                //找到合同的流程，删除流程
                flowService.deleByMainId(id);


                //删除合同
                this.removeById(id);
            }
        }
        return ResponseInfo.success();
    }

    @Override
    //    待办工作台预警 业务员角色   查询该用户是否有初审被驳回的合同
    public List<Contract> getCheckReturn(String userId) {
        if(StringUtils.isEmpty(userId)){
            return new ArrayList<>();
        }
        List<Contract> checkReturn = this.baseMapper.getCheckReturn(userId);
        return checkReturn;
    }

    @Override
    // 待办工作台预警 业务员角色   查询是否有快到期的合同
    public List<Contract> getExpireCaution(InputParam inputParam) {
        if(StringUtils.isEmpty(inputParam.getCurUserId())){
            return new ArrayList<>();
        }
        QueryWrapper ew = new QueryWrapper<Contract>();
        //合同已归档
        ew.eq("status",Contract.STATUS_FINISHED);
        //合同需要提醒
        if(!StringUtils.isEmpty(inputParam.getProject())){
            ew.like("project",inputParam.getProject());
        }
        ew.eq("is_expire_caution",1);
        ew.eq("creater",inputParam.getCurUserId());
        ew.lt("end_time", LocalDateTime.now().plusDays(30));
        ew.orderByAsc("end_time");
        //设置只查询40条
        ew.last("limit 40");
        List<Contract> checkReturn = this.list(ew);
        return checkReturn;
    }
    @Override
    public List<Contract> getTempContract(InputParam inputParam) {
        if(StringUtils.isEmpty(inputParam.getCurUserId())){
            return new ArrayList<>();
        }
        QueryWrapper ew = new QueryWrapper<Contract>();
        //临时合同
        ew.eq("status",Contract.STATUS_TEMP);
        ew.eq("creater",inputParam.getCurUserId());
        ew.orderByAsc("end_time");
        //设置只查询40条
        ew.last("limit 40");
        List<Contract> checkReturn = this.list(ew);
        return checkReturn;
    }
    @Override
    public void setNoRemind(InputParam inputParam) {
        if(StringUtils.isEmpty(inputParam.getId())){
            return ;
        }
        Contract contract = new Contract();
        contract.setId(inputParam.getId());
        contract.setIsExpireCaution(0);
        updateById(contract);
    }

    @Override
    public void setDefer(InputParam inputParam) {
        if(StringUtils.isEmpty(inputParam.getId()) ||inputParam.getEndEndTime()==null){
            return ;
        }
        Contract contract = new Contract();
        contract.setId(inputParam.getId());
        //合同的提醒字段要改为 0
        contract.setIsExpireCaution(0);
        updateById(contract);

        //查询当前合同的流程
        Flow current = flowService.getCurrent(inputParam.getId());
        if(current!=null && current.getStatusJunior().equals(Contract.STATUS_JUNIOR_RETURN)){
            //若是驳回后，重新提交，要记得修改流程的结束时间
            current.setEndTime(LocalDateTime.now());
            flowService.updateById(current);
        }
        //生成json数据，最后通过后录入表格
        contract.setEndTime(inputParam.getEndEndTime());
        contract.setIsExpireCaution(1);
        String jsonStr = JSON.toJSONString(contract);
        //创建流程，进入初审
        flowService.createWithJsonData(Flow.TYPE_CONTRACT_DEFER,Contract.STATUS_CHECK, Contract.STATUS_JUNIOR_DEAL,inputParam.getId(),
                inputParam.getCurUserId(),inputParam.getRemark(),jsonStr);

    }


}
